<!DOCTYPE html>
<html>
	{include file="public/_header" /}
	<script type="text/javascript" src="__STATIC__/kindeditor/kindeditor-all-min.js"></script>
	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-body ">
							<form class="layui-form" action="">
								<div class="layui-form-item">
									<label class="layui-form-label">标题</label>
									<div class="layui-input-block">
										<input type="text" name="title" required lay-verify="required" placeholder="[必填] 碎片标题/标题" autocomplete="off"
										 class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">名称</label>
									<div class="layui-input-block">
										<input type="text" name="name" required lay-verify="required" placeholder="[必填] 必须是英文/名称" autocomplete="off"
										 class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">排序</label>
									<div class="layui-input-block">
										<input type="number" name="sort" value="100" required lay-verify="required" placeholder="排序" autocomplete="off"
										 class="layui-input">
									</div>
								</div>
								<div class="layui-form-item layui-form-text">
									<label class="layui-form-label">描述</label>
									<div class="layui-input-block">
										<textarea placeholder="请输入内容" id="content" name="content" class="layui-textarea"></textarea>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-input-block">
										<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
										<button type="reset" class="layui-btn layui-btn-primary">重置</button>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
		<style type="text/css">
			.layui-upload-list {
				margin: 0 !important;
				float: left;
			}

			.layui-upload-img {
				width: 45px;
				height: 38px;
				margin: 0 10px;
				border: 1px solid #ddd
			}
		</style>
		<script type="text/javascript">
			$(function() {
				KindEditor.ready(function(K) {
					window.editor = K.create('#content',{
						uploadJson : "{:url('admin/Upload/addKindedit')}",
						fileManagerJson  : "{:url('admin/Filemanager/manager')}",
						allowFileManager : true,
						height:400,
						width:'100%'
					});
				});
			
				layui.use(['form', 'upload'], function() {
					var form = layui.form;
					var $ = layui.jquery,
						upload = layui.upload;

					//普通图片上传
					var uploadInst = upload.render({
						elem: '#test1',
						url: "{:url('admin/Upload/addImages')}",
						before: function(obj) {
							//预读本地文件示例，不支持ie8
							obj.preview(function(index, file, result) {
								$('#demo1').attr('src', result); //图片链接（base64）
							});
						},
						done: function(res) {
							if (res.status == 1) {
								$('#demo1').attr('src', "__STATIC__/admin/images/image.png");
								return layer.msg(res.message);
							} else {
								$("#logo").val(res.data);
							}
						},
						error: function() {
							//演示失败状态，并实现重传
							var demoText = $('#demoText');
							demoText.html(
								'<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
							demoText.find('.demo-reload').on('click', function() {
								uploadInst.upload();
							});
						}
					});
					//监听提交
					form.on('submit(formDemo)', function(obj) {
						if (obj.field.is_check) {
							obj.field.is_check = 1
						} else {
							obj.field.is_check = 0
						}
						var index = parent.layer.getFrameIndex(window.name);
						var lfc = top.layerFrameConfig;
						var info = lfc.iframeB.info;
						console.log(obj.field)
						$.post("{:url('admin/Block/add')}", obj.field, function(res) {
							if (res.status == 1) {
								layer.msg('添加成功', {
									icon: 1,
									time: 300
								}, function() {
									parent.layer.close(index); //再执行关闭
									info.reload()
								});

							} else {
								layer.msg(res.message)
							}
						})
						return false;
					});
				});


			})
		</script>

	</body>
</html>
